package users

import (
	"api/internal/respons"
	"context"
	"user_srv/userclient"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type CreateAchievementRuleLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewCreateAchievementRuleLogic(ctx context.Context, svcCtx *svc.ServiceContext) *CreateAchievementRuleLogic {
	return &CreateAchievementRuleLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *CreateAchievementRuleLogic) CreateAchievementRule(req *types.CreateAchievementRuleRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	rule, err := l.svcCtx.UserRpc.CreateAchievementRule(l.ctx, &userclient.CreateAchievementRuleRequest{
		Name:      req.Name,
		RuleDesc:  req.RuleDesc,
		Condition: req.Condition,
		Reward:    req.Reward,
		Status:    req.Status,
	})
	if err != nil {
		return respons.Error(400, "服务端错误", err.Error()), err
	}
	return respons.Success(rule), nil
}
